package com.yhq.basic.jvm.dataarea;

import com.yhq.basic.jvm.dataarea.po.Person;
import org.openjdk.jol.info.ClassLayout;

/**
 * 计算对象大小
 * -XX:+UseCompressedOops 默认开启的压缩所有指针
 * -XX:-UseCompressedOops 关闭所有压缩指针
 * ‐XX:+UseCompressedClassPointers 默认开启的压缩对象头里的类型指针Klass Pointer
 * ‐XX:-UseCompressedClassPointers 关闭Klass Pointer 压缩
 *
 * @author hqyin
 * @date 2023/3/7 3:52 下午
 */
public class Demo4JOLObjLayout {
    public static void main(String[] args) {
//        Object obj = new Object();
//        ClassLayout layout = ClassLayout.parseInstance(obj);
//        System.out.println(layout.toPrintable());
//        System.out.println("obj对象地址："+obj);
//        System.out.println("obj claas对象地址："+obj.getClass());
//        System.out.println();
//
//        int[] arr = new int[]{1,2};
//        ClassLayout layout1 = ClassLayout.parseInstance(arr);
//        System.out.println(layout1.toPrintable());
//        System.out.println("arr claas对象地址："+arr.getClass());
//        System.out.println();
//
//        A a = new A();
//        ClassLayout layout2 = ClassLayout.parseInstance(a);
//        System.out.println(layout2.toPrintable());
//        System.out.println("a claas对象地址："+a.getClass());

        Person person = new Person();
        ClassLayout layout3 = ClassLayout.parseInstance(person);
        System.out.println(layout3.toPrintable());
    }

    public static class A {
        int id;
        String name;
        byte b;
        short c;
        long d;
        double f;
        float g;
        Object o;

    }


}





